package apiv1

import (
	"news/pkg/web/apiv1/handler"
	"news/pkg/web/middleware"

	"github.com/gin-gonic/gin"
)

// @title 新闻管理系统
// @version 1.0.0
// @description 新闻管理系统

// @BasePath /api/v1
// @schemes http

// @securityDefinitions.apikey AuthToken
// @in header
// @name Authorization

func Register(g *gin.RouterGroup) {
	// 用户注册
	g.POST("/users/register", handler.UserRegister)
	// 用户登录

	g.POST("/users/login", handler.UserLogin)
	{
		g.POST("icons", handler.IconFileUpload)
		g.GET("/icons", handler.ReadIconFile)
	}
	// add before apis which need jwt auth
	g.Use(middleware.JwtAuth())
	{
		g.GET("/users/auth", handler.AuthMe)
		g.GET("/users", handler.SearchUser)
		g.PUT("/users", handler.UserUpdate)
		g.DELETE("/users/:id", handler.UserDelete)
		g.PUT("/users/updatePass", handler.UpdatePassword)
		g.PUT("/users/adminUpdate/:id", handler.AdminUpdate)

		g.DELETE("/users", handler.DeleteUsers)

		g.GET("/news", handler.SearchNews)
		g.GET("/news/:id", handler.GetNewsById)
		g.POST("/news", handler.CreateNews)
		g.DELETE("/news/:id", handler.DeleteNewsById)
		g.DELETE("/news", handler.DeleteNewsByIds)
		g.PUT("/news/:id", handler.UpdateNewsById)
		g.PUT("/news", handler.UpdateNewsStateByIds)

		g.GET("/news/getByUser/:id", handler.GetNewsByUserId)
		g.GET("/news/getNewsByState", handler.GetNewsByState)
		g.GET("/news/weekCount", handler.GetWeekNewsAddCount)
		g.GET("/news/getCountByType", handler.GetNewsCountByType)
		g.GET("/news/list", handler.GetNewsList)

		g.POST("/sens", handler.AddSensitiveWord)
		g.DELETE("/sens/:id", handler.DeleteSensById)
		g.DELETE("/sens", handler.DeleteSensByIds)
		g.PUT("/sens/:id", handler.UpdateSens)
		g.GET("/sens", handler.QuerySens)
		g.GET("/sensWords", handler.QuerySensWords)
	}

}
